package com.example.service.impl;


import com.example.mapper.UserMapper;
import com.example.model.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by yimi on 2016/12/19.
 */
@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserById(Integer id) {
        return userMapper.getUserById(id);
    }

    @Override
    public Integer addUser(String name,Integer age) {
        User users = new User();
        users.setAge(age);
        users.setName(name);
        return userMapper.addUser(users);
    }

    @Override
    public Integer updateUser(Integer id) {
        User user = getUserById(id);
        if(user == null){
            throw new RuntimeException("找不到该用户");
        }else {
            return userMapper.updateUser(user);
        }

    }

    @Override
    public String deleteUser(Integer id) {
        Integer result = userMapper.deleteUser(id);
       if(result > 0){
           return "删除成功";
       }else
       {
           return "删除失败";
       }
    }
}
